﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace MyNeighbourhood.RouteConstraints
{
    public class YearConstraint : IRouteConstraint
    {
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            int year;
            if (int.TryParse(values[parameterName].ToString(), out year))
            {
                if (year > 0 && year < DateTime.Now.Year)
                {
                    return true;
                }
            }

            return false;
        }
    }
}